package com.qiall.project.service.taskinfo;

import com.qiall.assertutil.Assert;
import com.qiall.common.request.BaseActivity;
import com.qiall.common.request.BaseResponse;
import com.qiall.project.ability.request.AddOrUpdateTaskRequest;
import com.qiall.project.ability.request.AddProjectRequest;
import com.qiall.user.ability.entity.UserInfoDTO;
import com.qiall.user.ability.service.organization.OrganizationService;
import com.qiall.user.ability.service.user.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;


/**
 * @author 吴金辉
 */
@Component
public class AddTaskCheckActivity extends BaseActivity<AddOrUpdateTaskRequest, BaseResponse> {
    @DubboReference
    private UserService userService;
    @DubboReference
    private OrganizationService organizationService;


    @Override
    public void handler(AddOrUpdateTaskRequest request, BaseResponse response) {
        notNullCheck(request);
        checkAuthority(request);
    }

    private void notNullCheck(AddOrUpdateTaskRequest request) {
        Assert.notNull(request.getTaskName(), "任务名称为空");
        Assert.notNull(request.getTaskType(), "任务类型为空");
        Assert.notNull(request.getTaskStatus(), "任务状态为空");
        Assert.notNull(request.getContext(),"内容为空");
    }

    private void checkAuthority(AddOrUpdateTaskRequest request) {
        UserInfoDTO userInfoDTO = userService.getUserInfoByAuthCode(request).getBody();
        Assert.notNull(userInfoDTO, "用户未登录");
    }


}
